<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>
  <script type="text/javascript">


      $(function(){
          $("#vipcarddatagrid").datagrid({
              url:'${pageContext.request.contextPath}/vipcard/findAll',
              remoteSort:false,
              toolbar:'#vipcardtoolbar',//工具栏
              pagination:true,
              fit:true,
              /*pagePosition:'bottom',*/
              pageSize:5,//每页显示的条数  要求书写的值必须是pageList中的一个元素
              pageList:[5,25,50,100,300],//定义下拉列表中的页码
              fitColumns:true,
              onLoadSuccess:function(){
                  $(".btn").linkbutton({
                      plain:true
                  })
              },

              columns:[[
                  {field:'CK',align:'center',checkbox:true},
                  {field:'id',title:'图片编号',width:200,sortable:true,align:'center'},
                  {field:'path',title:'路径',width:200,sortable:true,align:'center'},
                  {field:'name',title:'会员卡名称',width:100,sortable:true,align:'center'},
                  {field:'price',title:'价格',width:100,sortable:true,align:'center'},
                  {field:'time',title:'天数',width:100,sortable:true,align:'center'},
                  {field:'show',title:'展示',width:200,sortable:true,align:'center',formatter:function(value,row,index){
                        return "<img src='${pageContext.request.contextPath}/"+row.path+"' style='width:300px;height:150px'>"
                      }},
                  {title:"操作",field:"options",width:100,
                      formatter:function(value,row,index){
                          return "<a href='javascript:;' onclick='openUpdateVipcard("+JSON.stringify(row)+")' class='btn' data-options=\"iconCls:'icon-edit',\">修改</a>"
                              +"<a data-options=\"iconCls:'icon-edit'\" onClick=\"deleteVipcard('"+ row.id +"');\" href='javascript:;' class='btn'>删除</a>";
                      }}
              ]]
          })


      });
      //删除vipcard
      function deleteVipcard(id){
          $.messager.confirm('删除提示','确定要删除吗？？？',function(r){
              if(r){
                  $.post("${pageContext.request.contextPath}/vipcard/delete",{"id":id},function(){
                      $("#vipcarddatagrid").datagrid('reload');
                  })
              }
          })
      }

      //批量删除
      function deleteSome(){
          var rows=$("#bannerdatagrid").datagrid("getSelections");
          if(rows.length>0){
              $.messager.confirm('删除提示','确定要删除吗？？',function(r){
                  if(r){
                      var ids=[];
                      $.each(rows,function(index,row){
                          ids.push(row.id);
                      });
                      $.ajax({
                          url:"${pageContext.request.contextPath}/emp/deleteSome",
                          data:{id:ids},
                          dataType:"JSON",
                          method:'post',
                          traditional:true,
                          success:function(result){
                              $("#bannerdatagrid").datagrid('reload');
                          }
                      })
                  }
              })
          }else{
              alert("至少选择一项！！");
          }
      }

      //打开添加会员卡
      function openaddVipcard(){
          $("#addVipcardDialog").dialog({
              title:'添加轮播图',
              width:450,
              height:450,
              iconCls:'icon-man',
              href:'${pageContext.request.contextPath}/back/vipcard/addVipcard.jsp',
              buttons:[{
                  text:'添加',
                  iconCls:'icon-add',
                  handler:addVipcard
              },{
                  text:'关闭',
                  iconCls:'icon-cancel',
                  handler:function(){
                      $("#addVipcardDialog").dialog('close');
                  }
              }]
          })
      }

      //添加vipcard
      function addVipcard(){
          $("#addVipcardForm").form({
              url:'${pageContext.request.contextPath}/vipcard/save',
              onSubmit:function(){
                  return $("#addVipcardForm").form('validate');
              },
              success:function(){
                  $.messager.show({
                      title:'提示信息',
                      msg:'添加成功',
                      timeout:5000,
                      showType:'slide'
                  });
                  $("#addVipcardDialog").dialog('close');
                  $("#vipcarddatagrid").datagrid('reload');
              }
          });
          $("#addVipcardForm").form('submit');
      }
      //更新会员卡
      function updateVipcard(){
          $("#updateVipcardForm").form({
              url:'${pageContext.request.contextPath}/vipcard/update',
              onSubmit:function(){
                  return $(this).form('validate');
              },
              success:function(result){
                  console.log(result);
                  $.messager.show({
                      title:'提示信息',
                      msg:'更新成功',
                      timeout:5000,
                      showType:'slide'
                  });
                  $("#vipcarddatagrid").datagrid('reload');
              },
          });
          $("#updateVipcardForm").form('submit');
          $("#updateVipcardDialog").dialog('close');
      }

     function openUpdateVipcard(row){
         $("#updateVipcardDialog").dialog({
             title:'更新会员卡',
             width:450,
             height:450,
             iconCls:'icon-man',
             href:'${pageContext.request.contextPath}/back/vipcard/updateVipcard.jsp?id='+row.id,
             buttons:[{
                 text:'更新',
                 iconCls:'icon-add',
                 handler:updateVipcard
             },{
                 text:'关闭',
                 iconCls:'icon-cancel',
                 handler:function(){
                     $("#addVipcardDialog").dialog('close');
                 }
             }]
         })
     }
  </script>
</head>




<table id="vipcarddatagrid" ></table>
<div id="vipcardtoolbar">
  <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="openaddVipcard();">添加会员卡</a>
  <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="deleteSome();">删除选中</a>
</div>

<div id="addVipcardDialog"></div>
<div id="updateVipcardDialog"></div>

</form>

